var BaseJs = {
  /**
   * API
   */
  api: 'http://120.79.15.76/api/',
  /**
   * 滑到底部
   */
  slideBottom: function (callback, page) {
    $(window).bind("scroll", function () {
      if ($(document).scrollTop() + $(window).height() > $(document).height() - 20) {
        callback(++page)
      }
    })
  },
  /**
   * 返回上一页
   */
  goBack: function () {
    window.history.back();
  },
  /**
   * 动态计算REM
   */
  calRem: function () {
    var docEl = document.documentElement;
    var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
    var reCalc = function () {
      var width = 1920;
      var clientWidth = docEl.clientWidth;
      if (clientWidth <= 750) {
        width = 750;
      }
      if (clientWidth <= 1920 && clientWidth > 750) {
        width = 1920;
      }
      if (!clientWidth) {
        return;
      }
      docEl.style.fontSize = 20 * (clientWidth / width) + 'px';
    };
    if (!document.addEventListener) return;
    window.addEventListener(resizeEvt, reCalc, false);
    document.addEventListener('DOMContentLoaded', reCalc, false);
  },
  /**
   * 让当前导航栏active
   */
  navActive: function (number) {
    $('.navbar-nav ul li').eq(number).find('a').attr('class', 'active');
  },
  /**
   * 获取url参数
   */
  getUrlId: function (url) {
    return url.substring(url.indexOf('=') + 1, url.length);
  },
  /**
   * 
   */
  getUrlSearch: function (url) {
    return url.substring(url.indexOf('=') + 1, url.length);
  },
  /**
   * 获取公司信息
   */
  getCompanyInfo: function () {
    // http://www.senmo.vip/api/info
    $.get(this.api + 'info', function (data, status) {
      if (status == 'success') {
        var item = data.data;
        var phone = item.contact;
        var email = item.email;
        var intro = item.intro;
        $('.contact-phone').text(phone);
        $('.contact-email').text(email);
        $('.introduction-desc').text(intro);
      }
    })
  },
  /**
   * 侧滑菜单
   */
  getNavMenu: function () {
    var isOpenMenu = true;
    var navMenu = document.getElementsByClassName("navbar-nav")[0];
    var navToggle = document.getElementsByClassName("navToggle")[0];
    navToggle.onclick = function () {
      if (isOpenMenu) {
        $('.navbar-nav ul li').css('display', 'block');
        navMenu.style.width = "12rem";
        isOpenMenu = false;
      } else {
        $('.navbar-nav ul li').css("display", "none");
        navMenu.style.width = "0px";
        isOpenMenu = true;
      }
    }
  },

  searchBtnHover: function () {
    $("#search-btn").hover(function () {
      $('#search-input').css('width', '10rem')
      $('#search-input').css('border', '0.1rem solid #32484E')
      $('#search-input').css('padding-left', '0.8rem');
    }, function () {
      $('#search-input').css('width', '0')
      $('#search-input').css('border', '0')
      $('#search-input').css('padding', '0')
    })
    $('.navbar-search input').hover(function () {
      $('#search-input').css('width', '10rem')
      $('#search-input').css('border', '0.1rem solid #32484E')
      $('#search-input').css('padding-left', '0.8rem');
    }, function () {
      $('#search-input').css('width', '0')
      $('#search-input').css('border', '0')
      $('#search-input').css('padding', '0')
    })
  },
  /**
   * 判断IE10以下，提醒升级
   */
  isIE: function () {
    var isMSIE = window.navigator.userAgent.indexOf("MSIE") >= 0;
    if (isMSIE) {
      window.location.href = "./upgrade-your-browser.html";
    }
  },
  getData: function (url, callback) {
    $.get(url, function (data, status) {
      if (status === 'success') {
        console.log(data);
        console.log(url);
        callback(data.data);
      } else {
        console.log('获取数据出错' + url);
      }
    })
  },
  /**
   * 转换时间
   */
  timer_format: function (s) {
    var t = "";
    if (s > -1) {
      // hour = Math.floor(s / 3600);
      min = Math.floor(s / 60) % 60;
      sec = s % 60;
      if (min < 10) { t += "0"; }
      t += min + ":";
      if (sec < 10) { t += "0"; }
      t += sec;
    }
    return t;
  },
  /**
   * ID补0 
   */
  pad0: function (num) {
    var len = num.toString().length;
    if (len < 2) {
      return "0" + num;
    }
    return num;
  },
  /**
   * 
   */
  searchEvent: function (e) {
    e.preventDefault();
    var searchTxt = $('#search-input').val();
    if (searchTxt.replace(/\s+/g, "").length !== 0) {
      window.location.href = "./search.html?search=" + searchTxt;
    }
  },
  /**
   * header
   */
  htmlHeader: "<div class='navbar'>" +
    "<div class='navbar-brand'><div class='navbar-logo'><a href='./index.html'><img class='logo-img' src='images/ic_nav_logo@2x.png' alt='森茉文化传媒'></a></div>" +
    "<div class='navbar-title'></div><div class='navToggle'><img src='images/p_ic_menu@2x.png' alt=''></div></div>" +
    "<nav class='navbar-nav'><ul><li><a class='aNavIndex' href='./index.html'>首页</a></li><li><a href='./video.html'>视频</a></li>" +
    "<li><a href='./picture.html'>照片</a></li><li><a href='./vr-video.html'>全景视频</a></li><li><a href='./vr-picture.html'>全景照片</a></li>" +
    "<li class='about-us'><a href='./about.html'>关于森茉</a></li></ul></nav>" +
    "<div class='navbar-search'><form><input id='search-input' type='text' maxlength='16' placeholder='请输入你要查找的内容'><button id='search-btn' type='submit'></button>" +
    "</form></div></div>",
  /**
   * Footer
   */
  htmlFooter: "<div class='footer-contact'><div><p class='contact-us'>联系我们</p><p class='contact-company'>森茉文化传媒(深圳)有限公司</p></div>" +
    "<div class='contact-information'><div style='flex:1'></div>" +
    "<ul><li><img class='icon-address' src='images/p_ic_address@2x.png' alt=''><span class='contact-address'>深圳市</span></li>" +
    "<li><img class='icon-phone' src='images/p_ic_phone@2x.png' alt=''><span class='contact-phone'></span></li>" +
    "<li><img class='icon-email' src='images/p_ic_email@2x.png' alt=''><span class='contact-email'></span></li></ul></div></div>",
  /**
   * Footer-About
   */
  htmlFooterAbout: "<div class='footer-about'><div><img class='footer-logo' src='images/logo-2@2x.png' alt=''></div>" +
    "<div class='about-right'><div class='flex1'></div><p class='about-text'>关于森茉</p><p class='introduction-text'>森茉文化传媒（深圳）有限公司简介</p>" +
    "<p class='introduction-desc'></p><div class='flex1'></div></div></div>"
}